import { defineStore } from 'pinia';
import { isSurveyComName } from '@/utils';
import {
  setTextStatus,
  addOption,
  removeOption,
  setPosition,
  setFontSize,
  setFontWeight,
  setFontItalic,
  setFontColor,
  setOptionLink,
  addPicOption,
  setTextType,
  setOptionIsUse,
  setDateTime,
} from './actions';

export const useEditorStore = defineStore('editor', {
  state: () => ({
    currentComponentIndex: -1, // 一开始没有选中的组件
    surveyCount: 0, // 用于对问题进行计数
    coms: [],
  }),
  actions: {
    addCom(newCom) {
      this.coms.push(newCom);
      this.currentComponentIndex = -1;
      if (isSurveyComName(newCom.name)) {
        this.surveyCount++;
      }
    },
    initStore() {},
    setCurrentComponentIndex(index) {
      this.currentComponentIndex = index;
    },
    removeCom(){
      this.coms.slice(1,index)
    },
    setTextStatus,
    addOption,
    removeOption,
    setPosition,
    setFontSize,
    setFontWeight,
    setFontItalic,
    setFontColor,
    setOptionLink,
    addPicOption,
    setTextType,
    setOptionIsUse,
    setDateTime,
  },
});
